<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/head::head"></th:block>
    <style>
        .context {
            height: 80vh;
        }
    </style>
</head>

<body>
<form action="" class="layui-form" id="">
    <div class="layui-form-item">
        <label class="layui-form-label">配置内容</label>
        <div class="layui-input-block">
                        <textarea name="content" required lay-verify="required" placeholder=""
                                  class="layui-textarea context" th:text="${content}"></textarea>
        </div>
    </div>
    <div class="layui-form-item" style="padding-left: 20%">
        <button class="layui-btn" lay-submit lay-filter="submit" id="submit">保存
        </button>
        <button class="layui-btn" lay-submit lay-filter="submit" id="submitRestart">保存并重启
        </button>
    </div>
</form>
</body>
<script type="text/javascript"
        th:src="@{${session.jpomProxyPath}+'/static/js/auto-line-number.js?v='+${session.staticCacheTime}}"></script>

<script type="text/javascript">

    function loadSuccess() {
        initPlugin();
        $("textarea").setTextareaCount({
            width: "30px",
            bgColor: "#ddd",
            color: "#000",
            display: "inline-block"
        });

        //提交配置信息
        form.on('submit(submit)', function (data) {
            var attr = $(data.elem).attr("id");
            var restart = attr.indexOf("Restart") !== -1;
            console.log(data.field);
            loadingAjax({
                url: './save_config.json',
                data: {
                    content: data.field.content,
                    restart: restart
                },
                success: function (data) {
                    layer.msg(data.msg);
                    if (200 === data.code) {
                        if (restart) {
                            top.layer.msg('系统重启中..', {
                                icon: 16,
                                shade: 0.2,
                                time: 1000 * 30,
                                end: function () {
                                    top.location.reload();
                                }
                            });
                        }
                    }
                }
            });
            return false;
        });
    }

</script>

</html>